package com.tao.com.xiaowen.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.tao.com.xiaowen.model.Comment;
import com.tao.com.xiaowen.R;

import java.util.List;

/**
 * Created by Administrator on 2016/8/16.
 */
public class JokeCommentAdapter extends RecyclerView.Adapter<JokeCommentAdapter.CommentViewHolder>{
    private Context context;
    private List<Comment> commentList;
    private LayoutInflater inflater;

    public JokeCommentAdapter(Context context,List<Comment> commentList){
        this.context = context;
        this.commentList = commentList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public CommentViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.activity_joke_comment_item,null);
        CommentViewHolder holder = new CommentViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final CommentViewHolder holder, int position) {
        final Comment comment = commentList.get(position);
        holder.userName.setText(comment.getNickname());
        holder.commentContent.setText(comment.getCommentContent());
        Glide.with(context).load(comment.getFigureurl_qq_1())
                .into(holder.userPic);

    }

    @Override
    public int getItemCount() {
        return commentList.size();
    }

    class CommentViewHolder extends RecyclerView.ViewHolder{
        private ImageView userPic;
        private TextView userName;
        private TextView commentContent;

        public CommentViewHolder(View itemView) {
            super(itemView);
            userPic = (ImageView) itemView.findViewById(R.id.user_picture);
            userName = (TextView) itemView.findViewById(R.id.user_nick);
            commentContent = (TextView) itemView.findViewById(R.id.comment_content);
        }
    }
}
